import posts, { type IArticle } from './posts';

const lookup = new Map();
posts.forEach((post) => {
	lookup.set(post.slug, post);
});

export default {
	get(slug: string): IArticle {
		return lookup.get(slug);
	},

	has(slug: string): boolean {
		return lookup.has(slug);
	},

	list(slug: string): IArticle[] {
		let newposts = posts.filter((post) => {
			return post.module == slug;
		});
		if (newposts.length == 0) {
			newposts = posts;
		}
		return newposts;
	}
};
